package com.zr.controller.sys;

import com.github.pagehelper.PageInfo;
import com.zr.service.sys.SysRoleService;
import com.zr.utils.AjaxResult;
import com.zr.vo.sys.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 用户角色处理
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {
    
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 条件查询角色列表
     * @param sysRole
     * @return
     */
    @RequestMapping("/list")
    public AjaxResult list(@RequestBody SysRole sysRole){
        PageInfo<SysRole> pageInfo = sysRoleService.list(sysRole);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 查询所有角色
     * @return
     */
    @RequestMapping("/listAll")
    public AjaxResult listAll(){
        List<SysRole> sysRoleList = sysRoleService.listAll();
        return AjaxResult.success(200, "查询成功", sysRoleList);
    }

    /**
     * 新增角色
     * @param sysRole
     * @return
     */
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody SysRole sysRole){
        sysRoleService.add(sysRole);
        return AjaxResult.success(200, "新增成功", null);
    }

    /**
     * 编辑角色
     * @param sysRole
     * @return
     */
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody SysRole sysRole){
        sysRoleService.edit(sysRole);
        return AjaxResult.success(200, "修改成功", null);
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @RequestMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Integer id){
        sysRoleService.remove(id);
        return AjaxResult.success(200, "删除成功", null);
    }


}
